<?php if (!defined('THINK_PATH')) exit();?><form id="pagerForm" action="__URL__" method="post">
	<input type="hidden" name="pageNum" value="1"/>
	<input type="hidden" name="_order" value="<?php echo ($_REQUEST["_order"]); ?>"/>
	<input type="hidden" name="_sort" value="<?php echo ($_REQUEST["_sort"]); ?>"/>
    <input type="hidden" name="numPerPage" value="<?php echo ($_REQUEST["numPerPage"]); ?>" />
</form>

<script type="text/javascript">
<!--
var total_amount1 = $("input[name=total_amount1]");
var total_amount2 = $("input[name=total_amount2]");
var total_nums1 = $("input[name=total_nums1]");
var total_nums2 = $("input[name=total_nums2]");
$(function(){
	total_amount1.val((0).toFixed(2));
    total_amount2.val((0).toFixed(2));
    total_nums1.val(0);
    total_nums2.val(0);
});

function calculate(t, del){    
    var tbody = $(t).parents('tbody');    
    
    var total1 = 0;
    var total2 = 0;
    var totalnums1 = 0;
    var totalnums2 = 0;
    var fix1 = 0;
    var fix2 = 0;  
    var fixnums1=0;// 刪除的話應該忽略本行
    var fixnums2=0;// 刪除的話應該忽略本行
    if (del == 1){
        //alert(0);
        $(t).parents("tr:first").each(function(){
            var orgCount1 = 0;
            var orgCount2 = 0;
            var orgPrice1 = 0;
            var orgPrice2 = 0;
            var orgTotal1 = 0;
            var orgTotal2 = 0;
            $(this).find('input').each(function(){
                if (this.name == 'items1.orgCount[]') orgCount1 = this.value == '' ? 0 : this.value;
                if (this.name == 'items2.orgCount[]') orgCount2 = this.value == '' ? 0 : this.value;
                if (this.name == 'items1.inmaxprice[]') orgPrice1 = this.value == '' ? 0 : this.value;
                if (this.name == 'items2.inmaxprice[]') orgPrice2 = this.value == '' ? 0 : this.value;
                if (this.name == 'items1.orgTotal[]'){
                    orgTotal1 = orgCount1*orgPrice1;
                    if (orgTotal1 == 0){
                        this.value = '';
                    } else {
                        this.value = orgTotal1.toFixed(2);
                    }
                }
                if (this.name == 'items2.orgTotal[]'){
                    orgTotal2 = orgCount2*orgPrice2;
                    if (orgTotal2 == 0){
                        this.value = '';
                    } else {
                        this.value = orgTotal2.toFixed(2);
                    }
                }
            });
            fix1 = orgTotal1;
            fix2 = orgTotal2;
            fixnums1 =orgCount1;
            fixnums2 =orgCount2;
        });
    }
    
    $(tbody).find('tr').each(function(){
        var orgCount1 = 0;
        var orgCount2 = 0;
        var orgPrice1 = 0;
        var orgPrice2 = 0;
        var orgTotal1 = 0;
        var orgTotal2 = 0;
        $(this).find('input').each(function(){
            if (this.name == 'items1.orgCount[]') orgCount1 = this.value == '' ? 0 : 1*this.value;
            if (this.name == 'items2.orgCount[]') orgCount2 = this.value == '' ? 0 : 1*this.value;
            if (this.name == 'items1.inmaxprice[]') orgPrice1 = this.value == '' ? 0 : this.value;
            if (this.name == 'items2.inmaxprice[]') orgPrice2 = this.value == '' ? 0 : this.value;
            if (this.name == 'items1.orgTotal[]'){
                orgTotal1 = orgCount1*orgPrice1;
                if (orgTotal1 == 0){
                    this.value = '';
                } else {
                    this.value = orgTotal1.toFixed(2);
                }
            }
            if (this.name == 'items2.orgTotal[]'){
                orgTotal2 = orgCount2*orgPrice2;
                if (orgTotal2 == 0){
                    this.value = '';
                } else {
                    this.value = orgTotal2.toFixed(2);
                }
            }
        });
        
        total1 += orgTotal1;
        total2 += orgTotal2;
        totalnums1 +=orgCount1;
        totalnums2 +=orgCount2;
    });
    
    if (fix1 != 0){
        total1 -= fix1;
        totalnums1 -= fixnums1;
    }
    if (fix2 != 0){
        total2 -= fix2;
        totalnums2 -= fixnums2;
    }
    
    if(totalnums1!=0){ total_nums1.val(totalnums1); }
    
    if(total1!=0){total_amount1.val(total1.toFixed(2));}
    
    if(totalnums2!=0){ total_nums2.val(totalnums2); }
    
    if(total2!=0){ total_amount2.val(total2.toFixed(2)); }
    
}
//-->
</script>
<h2 class="contentTitle">商品组装单(ZZ)</h2>
<form class="pageForm required-validate"  action="__URL__/addOrders/navTabId/__MODULE__" method="post" onsubmit="return validateCallback(this, dialogAjaxDone)">
<div class="pageContent">
	<div class="pageFormContent" layoutH="97">
    <fieldset>
        <table>
        <tr>
          <td>单据编号：</td>
          <td><input class="required" name="ordernumber" size="30" type="text" value="<?php echo ($newCode); ?>" /></td>
          <td>单据日期：</td>
          <td><input class="date" name="ordertime" type="text" value="<?php echo ($dtime); ?>" /><a class="inputDateButton" href="javascript:;">选择</a></td>
         </tr>
         <tr>
         <td>存货仓库：</td>
          <td>
          <input id="warehouse" name="warehouse.id" value="" type="hidden"/>
          <input class="required" name="warehouse.orgName" type="text" postField="keyword" suggestFields="id" size="30" readonly="true" />
	      <a class="btnLook" href="__APP__/Public/ckBackWarehouse/" lookupGroup="warehouse">查找带回</a>          
          </td>
          <td>经办人：</td>
          <td>
          <input id="orderUser" name="orderUser.id" value="" type="hidden"/>
          <input class="required" name="orderUser.orgName" type="text" postField="keyword" suggestFields="id"  readonly="true" />
	      <a class="btnLook" href="__APP__/Public/ckBackUser/" lookupGroup="orderUser">查找带回</a>          
          </td>
         </tr>
         <tr>
          <td>单据摘要：</td><td colspan="3"><input name="remarks" size="120" type="text" /></td>
         </tr>
        </table>
    </fieldset>
    <fieldset>
        <table class="list nowrap itemDetail" addButton="添加母件(入库)商品" width="100%">
        <thead>
        	<tr>
                <th type="text" name="items1.proid[]" fieldClass="readonly" readOnly="readonly" size="1">編 號</th>
        		<th type="lookup" name="items1.partnumber[]" lookupGroup="items1" lookupUrl="__APP__/Public/ckBackProducts/" suggestFields="orgNumber" readOnly size="20" fieldClass="required">商品編碼</th>
        		<th type="text" name="items1.prodname[]" fieldClass="readonly" size="25" readOnly="readonly">商品名稱</th>
        		<th type="text" name="items1.prodsize[]" fieldClass="readonly" readOnly="readonly">規 格</th>
                <th type="text" name="items1.partmodel[]" fieldClass="readonly" readOnly="readonly">型 号</th>
        		<th type="text" name="items1.unit[]" fieldClass="readonly" readOnly="readonly"size="2">單 位</th>
        		<th type="calculate" name="items1.orgCount[]" fieldClass="required" size="4">數 量</th>
        		<th type="calculate" name="items1.inmaxprice[]" size="5" fieldClass="required">单 价(￥)</th>
        		<th type="text" name="items1.orgTotal[]" size="8" fieldClass="required" readOnly="readonly">金 额(￥)</th>
                <th type="text" name="items1.orgMark[]" size="15">备 注</th>
        		<th onclick="calculate(this,1)" type="del" fieldClass="refreshAmount">删行</th>
        	</tr>
        </thead>
        <tbody></tbody>
        </table>
    </fieldset>
    <fieldset>
        <table class="list nowrap itemDetail" addButton="添加子件(出库)商品" width="100%">
        <thead>
        	<tr>
                <th type="text" name="items2.proid[]" fieldClass="readonly" readOnly="readonly" size="1">編 號</th>
        		<th type="lookup" name="items2.partnumber[]" lookupGroup="items2" lookupUrl="__APP__/Public/ckBackProducts/flag/XS" suggestFields="orgNumber" readOnly size="20" fieldClass="required">商品編碼</th>
        		<th type="text" name="items2.prodname[]" fieldClass="readonly" size="25" readOnly="readonly">商品名稱</th>
        		<th type="text" name="items2.prodsize[]" fieldClass="readonly" readOnly="readonly">規 格</th>
                <th type="text" name="items2.partmodel[]" fieldClass="readonly" readOnly="readonly">型 号</th>
        		<th type="text" name="items2.unit[]" fieldClass="readonly" readOnly="readonly"size="2">單 位</th>
        		<th type="calculate" name="items2.orgCount[]" fieldClass="required" size="4">數 量</th>
        		<th type="calculate" name="items2.inmaxprice[]" size="5" fieldClass="required">单 价(￥)</th>
        		<th type="text" name="items2.orgTotal[]" size="8" fieldClass="required" readOnly="readonly">金 额(￥)</th>
                <th type="text" name="items2.orgMark[]" size="15">备 注</th>
        		<th onclick="calculate(this,1)" type="del" fieldClass="refreshAmount">删行</th>
        	</tr>
        </thead>
        <tbody></tbody>
        </table>
    </fieldset>
    </div>
	<div class="formBar">
    <label style="float:left">入库量:<input name="total_nums1" size="5" type="text" readonly="readonly" /></label>
    <label style="float:left">出库量:<input name="total_nums2" size="5" type="text" readonly="readonly" /></label>
    <label style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <!--<label style="float:left">折扣金额:<input name="odd_amount" size="5" type="text" /></label>-->
    <label style="float:left">入库额:<input name="total_amount1" size="10" type="text" readonly="readonly" /></label>
    <label style="float:left">出库额:<input name="total_amount2" size="10" type="text" readonly="readonly" /></label>
    <label style="float:left"><input name="createManid" value="<?php echo ($_SESSION[C('USER_AUTH_KEY')]); ?>" type="hidden"/></label>
    <label style="float:left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label>
    <label style="float:left">制单人:<input name="createMan" size="10" value="<?php echo ($_SESSION['loginUserName']); ?>" size="5" type="text" readonly="true" /></label>    
	<label style="float: left;">&nbsp;&nbsp;&nbsp;是否结库:<input type="checkbox" checked="checked" id="goFunds" name="goFunds" value="1" /></label>
    <ul>
		<li><div class="buttonActive"><div class="buttonContent"><button type="submit">提交单据</button></div></div></li>
		<li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭退出</button></div></div></li>
	</ul>
	</div>
</div>
</form>